local skel = fk.CreateSkill {
  name = "emo__jidu",
}

Fk:loadTranslationTable{
  ["emo__jidu"] = "嫉妒",
  [":emo__jidu"] = "出牌阶段限一次，你可以令手牌数最大的一名其他角色本回合非锁定技失效，并随机获得其一半张手牌（向上取整）。",

  ["#emo__jidu-prompt"] = "嫉妒:令手牌数最大的一名其他角色非锁定技失效，随机获得其一半张手牌",
  ["@@emo__jidu-turn"] = "嫉妒:非锁失效",
}

skel:addEffect("active", {
  anim_type = "control",
  prompt = "#emo__jidu-prompt",
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to_select, selected)
    if #selected == 0 and to_select ~= player then
      local n = 0
      for _, p in ipairs(Fk:currentRoom().alive_players) do
        if p ~= player then
          n = math.max(n, p:getHandcardNum())
        end
      end
      return to_select:getHandcardNum() == n
    end
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity.."-turn")
    room:setPlayerMark(to, "@@emo__jidu-turn", 1)
    if not player.dead and not to:isKongcheng() then
      local x = (to:getHandcardNum() + 1) // 2
      local cards = table.random(to:getCardIds("h"), x)
      room:moveCardTo(cards, Player.Hand, player, fk.ReasonPrey, skel.name, nil, false, player)
    end
  end,
})

return skel
